package com.jiazhong.basic.pack0524.manytoone.service.impl;

import com.jiazhong.basic.pack0524.manytoone.bean.Dept;
import com.jiazhong.basic.pack0524.manytoone.bean.Emp;
import com.jiazhong.basic.pack0524.manytoone.dao.DeptDAO;
import com.jiazhong.basic.pack0524.manytoone.dao.EmpDAO;
import com.jiazhong.basic.pack0524.manytoone.service.EmpService;

public class EmpServiceImpl implements EmpService {

    private EmpDAO edao;
    private DeptDAO ddao;

    public EmpServiceImpl() {
        edao = new EmpDAO();
        ddao = new DeptDAO();
    }

    @Override
    public Emp findById1(int empNo) {
        // 1. 获取到了员工信息
        Emp emp = edao.findById1(empNo);
        // 2. 根据员工信息中的部门ID获取到对应的部门信息
        int deptNo = emp.getDeptNo();
        Dept dept = ddao.findById(deptNo);
        // 3. 组装
        emp.setDept(dept);
        return emp;
    }

    @Override
    public Emp findById2(int empNo) {
        return edao.findById2(empNo);
    }
}
